/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2012
 */

package com.tech15.pub.action;

import static javacommon.util.extjs.Struts2JsonHelper.outXmlJson;

import java.util.Map;

import javacommon.util.ResInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.org.rapid_framework.beanutils.BeanUtils;
import cn.org.rapid_framework.web.scope.Flash;

import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.ModelDriven;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import com.tech15.pub.model.*;
import com.tech15.pub.dao.*;
import com.tech15.pub.service.*;
import com.tech15.pub.vo.query.*;

/**
 * @author 胡作正 email:zuozhenghu@sina.com
 * @version 1.0
 * @since 1.0
 */


public class MeetingAuthAction extends BaseStruts2Action implements Preparable,ModelDriven{
	//默认多列排序,example: username desc,createTime asc
	protected static final String DEFAULT_SORT_COLUMNS = null; 
	
	//forward paths
	protected static final String LIST_JSP= "/pub/meetingAuth_list.jsp";
	protected static final String CREATE_JSP = "/pub/meetingAuth_add.jsp";
	protected static final String EDIT_JSP = "/pub/meetingAuth_edit.jsp";
	protected static final String SHOW_JSP = "/pub/meetingAuth_show.jsp";
	//redirect paths,startWith: !
	protected static final String LIST_ACTION = "!/meetingAuth/list.do";
	
	private MeetingAuthManager meetingAuthManager;
	
	private MeetingAuth meetingAuth;
	Long id = null;
	private String[] items;

	public void prepare() throws Exception {
		if (isNullOrEmptyString(id)) {
			meetingAuth = new MeetingAuth();
		} else {
			meetingAuth = (MeetingAuth)meetingAuthManager.getById(id);
		}
	}
	
	/** 增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,注意大小写 */
	public void setMeetingAuthManager(MeetingAuthManager manager) {
		this.meetingAuthManager = manager;
	}	
	
	public Object getModel() {
		return meetingAuth;
	}
	
	public void setId(Long val) {
		this.id = val;
	}

	public void setItems(String[] items) {
		this.items = items;
	}
	
	/** 执行搜索 */
	public String list() {
		MeetingAuthQuery query = newQuery(MeetingAuthQuery.class,DEFAULT_SORT_COLUMNS);
		
		Page page = meetingAuthManager.findPage(query);
		savePage(page,query);
		return LIST_JSP;
	}
	
	/** 查看对象*/
	public String show() {
		return SHOW_JSP;
	}
	
	/** 进入新增页面*/
	public String create() {
		return CREATE_JSP;
	}
	
	public void getAuth(){
		Integer count = meetingAuthManager.getAuth(getLoginInfo().getUserid());
		getRequest().setAttribute("meetingAuth", count);
	}
	
	
	/** 保存新增对象 */
	public void save() {
		Map<String, Object> resInfo = null;
		try{
			meetingAuthManager.save(meetingAuth);
			resInfo = ResInfo.getResInfo("",false, false, 2, this.OPERATE_SUCCESS,"");
		}catch(Exception e){
			e.printStackTrace();
			resInfo = ResInfo.getResInfo("",false, false, 1, this.OPERATE_FAILED,"");
		}
		outXmlJson(resInfo);
	}
	
	/**进入更新页面*/
	public String edit() {
		return EDIT_JSP;
	}
	
	/**保存更新对象*/
	public void update() {
		Map<String, Object> resInfo = null;
		try{
			meetingAuthManager.update(this.meetingAuth);
			resInfo = ResInfo.getResInfo("",false, false, 2, this.OPERATE_SUCCESS,"");
		}catch(Exception e){
			e.printStackTrace();
			resInfo = ResInfo.getResInfo("",false, false, 1, this.OPERATE_FAILED,"");
		}
		outXmlJson(resInfo);
	}
	
	/**删除对象*/
	public void delete() {
		Map<String, Object> resInfo = null;
		try {
			meetingAuthManager.removeById(id);
			resInfo = ResInfo.getResInfo("",false, false, 2, this.OPERATE_SUCCESS,"");
		} catch (Exception e) {
			e.printStackTrace();
			resInfo = ResInfo.getResInfo("",false, false, 1,this.OPERATE_FAILED,"");
		}		
		outXmlJson(resInfo);
	}
	
}
